// import axios from 'axios'
export default {
  namespaced: true,
  state () {
    return {
      goodList: [
        {
          name: '诸葛亮',
          price: 1000,
          num: 1,
          checked: false,
          id: 1
        },
        {
          name: '蔡文姬',
          price: 1500,
          num: 1,
          checked: false,
          id: 2
        },
        {
          name: '妲己',
          price: 2000,
          num: 1,
          checked: false,
          id: 3
        },
        {
          name: '鲁班',
          price: 2200,
          num: 1,
          checked: false,
          id: 4
        }
      ]
    }
  },
  mutations: {
    updateNum (state, obj) {
      const goods = state.goodList.find((item) => item.id === obj.id)
      goods.num = obj.num
    }
  },
  actions: {
    updateNum (state, obj) { state.commit('updateNum', obj) }
  },
  getters: {
    totalPrice (state) {
      return state.goodList.reduce((p, c) => p + c.num * c.price, 0)
    }
  }
}
